package com.kitty.game.reward.model;

import lombok.Getter;
import lombok.Setter;
import org.codehaus.jackson.annotate.JsonIgnore;

import java.util.List;

@Getter
@Setter
public class RewardSet {
    private List<RewardUnitSet> list;
    @JsonIgnore
    private String desc;
    /**需要包裹格子数量*/
    @JsonIgnore
    private int bagPosCount = -1;
    /**需要宠物格子数量*/
    @JsonIgnore
    private int petPosCount = -1;

    public String getDesc() {
        if (desc == null) {
            initDesc();
        }
        return desc;
    }

    private void initDesc() {
        StringBuilder stringBuilder = new StringBuilder();
        for (RewardUnitSet rewardUnitSet : list) {
            stringBuilder.append(rewardUnitSet.getDesc());
        }
        desc = stringBuilder.toString();
    }

    public int getBagPosCount() {
        if (bagPosCount == -1) {
            initBagPosCount();
        }
        return bagPosCount;
    }

    private void initBagPosCount() {
        int posCount = 0;
        for (RewardUnitSet rewardUnitSet : list) {
            posCount += rewardUnitSet.getPosCount();
        }

        bagPosCount = posCount;
    }

    public int getPetPosCount() {
        if (petPosCount == -1) {
            initPetPosCount();
        }
        return petPosCount;
    }

    private void initPetPosCount() {
        int posCount = 0;
        for (RewardUnitSet rewardUnitSet : list) {
            posCount += rewardUnitSet.getPetPosCount();
        }

        petPosCount = posCount;
    }
}
